package com.ky.pro.java.dt.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ky.pro.java.dt.common.web.ResultBean;
import com.ky.pro.java.dt.order.entity.Order;
import com.ky.pro.java.dt.order.mapper.OrderMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 配餐处理表 服务实现类
 * </p>
 *
 * @author Kevin Dummy
 * @since 2021-12-26
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IService<Order> {

    @Autowired
    OrderMapper orderMapper;


    public ResultBean<Boolean> checkExistence(long orderNo) {
        QueryWrapper<Order> cond = new QueryWrapper<Order>().eq("order_no", orderNo);
        return ResultBean.genResult(orderMapper.selectCount(cond));
    }

    /**
     * 更改订单状态
     *
     * @param orderNo
     * @param status
     * @return
     */
    public ResultBean<String> updateOrderStatus(long orderNo, int status) {
        int updateResult = orderMapper.updateByOrderNo(orderNo, status);
        return updateResult > 0 ? ResultBean.genResult("更新成功") : ResultBean.genError("更新失败");
    }

}
